<?php

class SoapserverController extends Zend_Controller_Action {

  const ACTION_WSDL = 'wsdl';
  const ACTION_WEBSERVICE = 'webservice';
  const CLASS_SERVICE = 'App_WebService_Methods';

  public function init() {
    $this->_helper->viewRenderer->setNoRender(true);
    $this->_helper->layout->disableLayout();
  }

  public function indexAction() {
    $url = 'http://vw-group.pl/';
    $this->_helper->redirector->gotoUrlAndExit($url);
  }

  public function wsdlAction() {
    $wsdl = file_get_contents('vgp_hr.wsdl');
    Header('Content-Type: text/xml');
    Header('Content-Length: ' . strlen($wsdl));
    echo $wsdl;
  }

  public function webserviceAction() {
    $options = array(
        'encoding' => 'UTF-8',
        'cache_wsdl' => WSDL_CACHE_NONE,
        'features' => SOAP_SINGLE_ELEMENT_ARRAYS,
        'classmap' => array(
	        	// Data
	        	'App' => 'App_WebService_Data_App',
	        	// Request
    				'SetApplicationData' => 'App_WebService_Request_SetApplicationData'
        )
    );
    $url = $this->view->serverUrl() . $this->view->url(array("action" => self::ACTION_WSDL), null, true);
    $soap = new Zend_Soap_Server($url, $options);
    $soap->setClass(self::CLASS_SERVICE);
    $soap->setObject(new App_WebService_Caller());
    $soap->registerFaultException('App_Exception_App', 'App_Exception_Php');
    $soap->handle();
  }

}

?>
